// 引入登录接口
import { loginApi } from '@/api/userLoginApi'
export default {
  namespaced: true,
  state: {
    token: '',
    userInfo: {},
    userRole: []

  },
  getters: {

  },
  mutations: {
    // 登录成功
    LoginSuccess (state, payLoad) {
      state.token = payLoad.token
      state.userInfo = payLoad.userInfo
    },
    // 登录退出清空
    resetLogin (state) {
      state.token = ''
      state.userInfo = {}
    }
  },
  actions: {
    // 异步登录
    async LoginAction (store, payLoad) {
      const result = await loginApi(payLoad)
      console.log(result, '异步action;;')
      if (result.userInfo) {
        store.commit('LoginSuccess', result)
        return true
      } else {
        store.commit('resetLogin')
        return false
      }
    }

  },
  modules: {

  }
}
